home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC15CDevSamples / APWC / CDev.cc next >
Encoding:
C/C++ Source or Header  |  1990-05-25  |  8.8 KB  |  198 lines  |  [04] ASCII Text (0x0000)

  1. /*###########################################################*/
  2. /*#                                                         #*/
  3. /*# File:           CDev.c                                  #*/
  4. /*# Version:        3.0                                     #*/
  5. /*# Author:                                                 #*/
  6. /*# Copyright:      (c) 1989 by Apple Computer, Inc.        #*/
  7. /*# Developer Technical Support Apple II Sample Code        #*/
  8. /*#                                                         #*/
  9. /*# Description:    This file contains the cdev C           #*/
  10. /*#                 routine used by the Shell CDEV.         #*/
  11. /*#                                                         #*/
  12. /*#---------------------------------------------------------#*/
  13. /*#                                                         #*/
  14. /*# Development History:                                    #*/
  15. /*#                                                         #*/
  16. /*# Who     Date        The Modification                    #*/
  17. /*# ---     --------    ----------------                    #*/
  18. /*#                                                         #*/
  19. /*###########################################################*/
  20.  
  21. #include <Types.h>
  22. #include <GSOS.h>
  23. #include <Quickdraw.h>
  24. #include <Font.h>
  25. #include <Memory.h>
  26. #include <IntMath.h>
  27. #include <Event.h>
  28. #include <ProDOS.h>
  29. #include <Locator.h>
  30. #include <Control.h>
  31. #include <Window.h>
  32. #include <List.h>
  33. #include <Scrap.h>
  34. #include <Dialog.h>
  35. #include <Menu.h>
  36. #include <Desk.h>
  37. #include <StdFile.h>
  38. #include <QDAUX.h>
  39. #include <Print.h>
  40. #include <MiscTool.h>
  41. #include <LineEdit.h>
  42. #include <Resources.h>
  43.  
  44. #include "CDEV.h"
  45.  
  46. /*###########################################################*/
  47. /*#     Actual CDEV, this is called by the control panel    #*/
  48. /*###########################################################*/
  49.  
  50. #define AboutID     0x1000
  51.  
  52. #define PopUpList   0x5000
  53. #define PopUp1      0x5001
  54. #define PopUp2      0x5002
  55. #define PopUp3      0x5003
  56. #define PopUp1Item1 0x5101
  57. #define PopUp1Item2 0x5102
  58. #define PopUp1Item3 0x5103
  59. #define PopUp1Item4 0x5104
  60. #define PopUp2Item1 0x5201
  61. #define PopUp2Item2 0x5202
  62. #define PopUp2Item3 0x5203
  63. #define PopUp3Item1 0x5301
  64. #define PopUp3Item2 0x5302
  65.  
  66.  
  67. int         _toolErr;       /* normally, this is defined in Start.obj */
  68.  
  69. /* This routine is eventually linked and then placed into a cdev code resource.
  70.   The only requirements are that this routine is at the beginning of the resource
  71.   so if the CDEV has any other routines they must follow this one.  The cdev's resource
  72.   fork is always opened when a call to the cdev is made.  The cdev can also assume
  73.   that the current port is set to the ctl panel window except in the boot message,
  74.   where quickdraw isn't even started, and in the about message, where it is the port
  75.   of the help window.  All normal managers will be stared up for all calls except
  76.   the boot call, which will only have miscTools & Resource Manager started. */
  77.  
  78. pascal long CDEV(message,data1, data2)
  79. int     message;
  80. long    data1;
  81. long    data2;
  82. {
  83.     int         retCode;
  84.     CtlRecHndl  tempCtl;
  85.     
  86.     retCode = 0;    /* initialize the function result to zero, so that we will work in
  87.                         future versions of the Control Panel! */
  88.  
  89.     switch(message) {
  90.         case BootCDEV:
  91.             /* If the wantBoot flag is set, this routine will be called during the
  92.               startup sequence.  The control panel takes care of drawing the "boot"
  93.               icon.  When this call is made, the machine state is bad at best.
  94.               QuickDraw is not even started up.  The parameters to this call are
  95.               undefined. */
  96.             break;
  97.  
  98.         case MachineCDEV:
  99.             /* This is called if the wantMachine bit is set in the CDEV flags.
  100.               It enables the CDEV to do further checking to see if it makes
  101.               sense for the CDEV to be visible to the user or not.  For instance,
  102.               if the CDEV controls a setting for some hardware, we could check to
  103.               see if the hardware is really connected.  The parameters are undefined
  104.               for this call and the result is passed back as the function result.  0 =
  105.               don't show this CDEV, <>0 = show this CDEV.  The control panel will do
  106.               some machine checking even before calling this routine by checking the
  107.               ROM version number against the machine field of the cdev flags resource */
  108.             break;
  109.  
  110.         case CreateCDEV:
  111.             /* If the wantCreate bit is set, this message is called with the control
  112.               panel's window ptr passed in data1.  The cdev must create any controls
  113.               it has during this call.  The CDEV's resource fork is open during this
  114.               call so resource manager calls can be made.  All controls rectangles
  115.               MUST be relative to 0,0.  The control panel handles offsetting controls
  116.               to the proper place in the window.  Initialization of the controls
  117.               needs to be done in the InitCDEV call.  Just create the controls in this
  118.               call. */
  119.             
  120.             tempCtl = NewControl2(data1,9,(long) PopUpList);
  121.             break;
  122.  
  123.         case InitCDEV:
  124.             /* If the wantInit flag is set, then this message is passed with data1 =
  125.               the control panel's window ptr.  By  this time the CreateCDEV call
  126.               will have been made and thus the controls used by the CDEV created.
  127.               This call enables the CDEV to initialize the controls before they are
  128.               displayed. */
  129.             
  130.             SetCtlValue(PopUp1Item1, GetCtlHandleFromID(data1, (long) PopUp1));
  131.             SetCtlValue(PopUp2Item1, GetCtlHandleFromID(data1, (long) PopUp2));
  132.             SetCtlValue(PopUp3Item1, GetCtlHandleFromID(data1, (long) PopUp3));
  133.             break;
  134.  
  135.         case AboutCDEV:
  136.             /* If the wantAbout bit is set in the CDEV flags, this call is made when
  137.               the user selects help.  Data1 = window ptr to the help window.  The
  138.               control panel automatically handles the icon, author, and version #
  139.               display.*/
  140.             
  141.             tempCtl = NewControl2(data1,2, (long) AboutID);
  142.             break;
  143.  
  144.         case RectCDEV:
  145.             /* If a CDEV has a different size data rectangle depending on some state,
  146.               like the printer & modem port cdev's, then you can get a chance to tell the
  147.               control panel this by setting the wantRect bit in the CDEV flags.  In
  148.               this call, data1 is a ptr to the rect and can be directly modified by
  149.               the CDEV. */
  150.             break;
  151.  
  152.         case EventsCDEV:
  153.             /* If the wantEvents bit is set, the control panel will call this routine
  154.               with data1 = ptr to the event record.  This allows the cdev to intercept
  155.               and even *gasp* change the event record before it is handled by the
  156.               control panel. */
  157.             break;
  158.  
  159.         case HitCDEV:
  160.             /* If the CDEV wants to know when a control has been "hit", it can set the
  161.               wantHit bit in the CDEV flags.  When called, data1 = Hdl to Ctl Hit &
  162.               data2 = Ctl ID of hit control.  This message allows the CDEV to perform
  163.               actions based on the control that was selected by the user.*/
  164.  
  165.             switch((int) data2) {
  166.                 case PopUp1:    break;  /*popup1*/
  167.                 case PopUp2:    break;  /*popup2*/
  168.                 case PopUp3:    break;  /*popup3*/
  169.             }
  170.             break;
  171.             
  172.         case RunCDEV:
  173.             /* This message is called if the "wantRun" bit is set in the CDEV flags.  It
  174.               enables CDEVs like time to update the display.  It is called every 60th of
  175.               a second - every time the DARun call is issued to the control panel. -no
  176.               parameters are passed to this routine. */
  177.             break;
  178.  
  179.         case CloseCDEV:
  180.             /* The CloseCDEV message is passed if the wantClose bit is set in the CDEV
  181.               flags and the control panel is closing or when the user selects another
  182.               CDEV.  During  this call data1 = windowPtr.  In general, CDEVs can do any
  183.               memory disposal and saving of settings during this call.  The disposal
  184.               of the CDEV's controls is handled automatically by the Control Panel. */
  185.             
  186.             break;
  187.  
  188.         case ShutDownCDEV:
  189.             /* If the wantShutDown bit is set in the CDEV flags resource then
  190.               this routine is called when the user either disables the CDEV or
  191.               *someday* when the machine is being turned off.  It gives the CDEV
  192.               a chance to turn itself off (or any hardware or software it controls).
  193.               The parameters are undefined in this call. */
  194.             break;
  195.     }   /* end of switch */
  196.     return(retCode);
  197. }   /* end of CDEV function */
  198.